/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Objects;

import GameEngine.GameConstants.Effect;
import GameEngine.GameConstants.Graphic;
import GameEngine.GameConstants.Material;
import GameEngine.GameConstants.Modifier;
import GameEngine.Vector;
import java.util.Iterator;


/**
 *
 * @author jh20
 */
public class Chompers extends GameObject {

    private boolean chomping; // determines whether the chomper is retracting
    private float endPosition;
    private float cPosition;
    private float chompSpeed;

    /**
     * A constructor
     * @param m
     * @param min
     * @param max
     */
    public Chompers(Vector d, Vector cen, Vector s) {
        super(d, cen, s, Graphic.CHOMPERS);
        velocity = direction.scaleNew(chompSpeed);
        material = Material.SPIKY;
    }


    /* sets chomping attributes */
    public void setChompers(float end, float speed) {
        endPosition = end;
        cPosition = 0;
        chompSpeed = speed;
    }


    /**
     * Moves the chomper towards a given direction
     */
    @Override
    public void nextIteration() {
        // first apply persitent
        super.applyPersistent();
        // chomping
        if (chomping) {
            velocity = direction.scaleNew(chompSpeed);
            cPosition += chompSpeed;
            // check if at end position
            if (cPosition >= endPosition) {
                chomping = false;
            }
        }
        // else retracting
        else {
            velocity = direction.scaleNew(-chompSpeed);
            cPosition -= chompSpeed;
            // check if back at origin
            if (cPosition <= 0) {
                chomping = true;
            }
        }
        // now call super
        super.doPhysics();
        // now undo effects
        super.cancelPersistent();
    }



    @Override
    public void receiveEffect(Effect e, Vector m, int power) {
        switch (e) {
            case SPEED:
                chompSpeed += power;
                break;
            case SLOW:
                chompSpeed -= power;
            default:
                // default is nothing happens
                break;
        }
    }


    @Override
    public void collide(GameObject o) {
        switch(o.material) {
            case SPIKY:
                chomping = false;
                break;
            default:
                // do nothing
                break;
        }
    }
    


}
